package img 
{
	import com.greensock.events.LoaderEvent;
	import com.greensock.loading.ImageLoader;
	import com.greensock.loading.LoaderMax;
	import flash.display.Bitmap;
	import flash.display.Sprite;
	import ru.gosoplata.model.TmpModel;
	/**
	 * TODO: LoadedImages - переписать на перья.
	 * @author a.orleansky
	 */
	public class LoadedImages extends Sprite
	{		
		private const _path:String = TmpModel.IMG_FOLDER;
		private const _picsInfo:Object = 	{
											//new Array("input_plane_left", path+"/input_tel/images/input_tel_left.png"),
											//new Array("input_plane_right", path+"/input_tel/images/input_tel_right.png"),
											//new Array("input_plane_center", path+"/input_tel/images/input_tel_center.png"),
											//new Array("input_plane_chek_right", path+"/input_tel/images/input_tel_chek_right.png"),
											//new Array("input_plane_chek_left", path+"/input_tel/images/input_tel_chek_left.png"),
											//new Array("input_plane_chek_center", path+"/input_tel/images/input_tel_chek_center.png"),
											
											//new Array("plane_right", path+"/input_tel/images/plane_right.png"),
											//new Array("plane_left", path+"/input_tel/images/plane_left.png"),
											//new Array("plane_center", path+"/input_tel/images/plane_center.png"),
											//new Array("plane_chek_right", path+"/input_tel/images/Krasnay3.png"),
											//new Array("plane_chek_left", path+"/input_tel/images/Krasnay1.png"),
											//new Array("plane_chek_center", path+"/input_tel/images/Krasnay2.png"),
											
											//new Array("plane_uni_right", path+"/input_tel/images/plane_blag_right.png"),
											//new Array("plane_uni_left", path+"/input_tel/images/plane_blag_left.png"),
											//new Array("plane_uni_center", path+"/input_tel/images/plane_blag_center.png"),
											
											//new Array("input_plane_chek", path+"/input_tel/images/chek.png"),
											"kb_icon_lang_eng":	{ path:	_path + "/keyboard_operatori/icon_lang_eng.png"},
											"kb_icon_lang_rus":	{ path:	_path + "/keyboard_operatori/icon_lang_rus.png"},
											"wc_closed":		{ path:	_path + "/blagorim_za_ispolzovanie/images/icon_tul_non.png"},
											"checkableplane":	{ path:	_path + "/service/check_plane.png"}
											};
		
		
		[Embed(source = "../../lib/pic/chek.png")]
		private const Img1:Class;
		[Embed(source = "../../lib/pic/input_tel_center.png")]
		private const Img2:Class;
		[Embed(source = "../../lib/pic/input_tel_chek_center.png")]
		private const Img3:Class;
		[Embed(source="../../lib/pic/input_tel_chek_left.png")]
		private const Img4:Class;
		[Embed(source = "../../lib/pic/input_tel_chek_right.png")]
		private const Img5:Class;
		[Embed(source = "../../lib/pic/input_tel_left.png")]
		private const Img6:Class;
		[Embed(source = "../../lib/pic/input_tel_right.png")]
		private const Img7:Class;
		[Embed(source = "../../lib/pic/Krasnay1.png")]
		private const Img8:Class;
		[Embed(source = "../../lib/pic/Krasnay2.png")]
		private const Img9:Class;
		[Embed(source = "../../lib/pic/Krasnay3.png")]
		private const Img10:Class;
		[Embed(source = "../../lib/pic/plane_blag_center.png")]
		private const Img11:Class;
		[Embed(source = "../../lib/pic/plane_blag_left.png")]
		private const Img12:Class;
		[Embed(source = "../../lib/pic/plane_blag_right.png")]
		private const Img13:Class;
		[Embed(source = "../../lib/pic/plane_center.png")]
		private const Img14:Class;
		[Embed(source = "../../lib/pic/plane_left.png")]
		private const Img15:Class;
		[Embed(source = "../../lib/pic/plane_right.png")]
		private const Img16:Class;
		
		public function LoadedImages() 
		{
			placeImage((new Img1() as Bitmap), "input_plane_chek");
			placeImage((new Img2() as Bitmap), "input_plane_center");
			placeImage((new Img3() as Bitmap), "input_plane_chek_center");
			placeImage((new Img4() as Bitmap), "input_plane_chek_left");
			placeImage((new Img5() as Bitmap), "input_plane_chek_right");
			placeImage((new Img6() as Bitmap), "input_plane_left");
			placeImage((new Img7() as Bitmap), "input_plane_right");
			placeImage((new Img8() as Bitmap), "plane_chek_left");
			placeImage((new Img9() as Bitmap), "plane_chek_center");
			placeImage((new Img10() as Bitmap), "plane_chek_right");
			placeImage((new Img11() as Bitmap), "plane_uni_center");
			placeImage((new Img12() as Bitmap), "plane_uni_left");
			placeImage((new Img13() as Bitmap), "plane_uni_right");
			placeImage((new Img14() as Bitmap), "plane_center");
			placeImage((new Img15() as Bitmap), "plane_left");
			placeImage((new Img16() as Bitmap), "plane_right");
		}
		
		public function preload(callBack:Function=null):void 
		{
			var greenloader:LoaderMax = new LoaderMax( { name:"maxloader", onComplete:callBack, onError:onLoadError } );//, onProgress:progressHandler
			for (var imgName:String in _picsInfo) 
			{
				var info:Object = _picsInfo[imgName];
				if(info["path"] && !info["bitmap"]){
					greenloader.append(new ImageLoader(info["path"],{name:imgName,onComplete:onImageLoaded}));
				}
			}
			greenloader.load();
		}
		
		private function onImageLoaded(e:LoaderEvent):void 
		{
			placeImage((e.target as ImageLoader).rawContent, e.target.name);
		}
		
		private function onLoadError(event:LoaderEvent):void 
		{
			TmpModel.acceptor.writeLog("LoadedImages. ERROR: " + event.text);
		}
		
		private function placeImage(bmp:Bitmap, imgName:String):void 
		{
			var info:Object = _picsInfo[imgName];
			if (!info) info = _picsInfo[imgName] = new Object();
			info["bitmap"] = bmp;
		}	
		
		public function getBitmapDataByName(imgName:String):Bitmap 
		{
			return _picsInfo[imgName]["bitmap"] as Bitmap;
		}
	}

}